package zezutom.joker.model;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

/**
 * No comment.
 * 
 * @author tomasz
 */
@Entity
@Table(name="jokes")
public class Joke implements Serializable {

    public static final String TO_STRING_FORMAT = "%s, %s";
    
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private Long id;
    
    @Column(name="joke_name")
    private String name;
    
    @Column
    @Enumerated(EnumType.STRING)
    private JokeSeverity severity;

    @ManyToOne
    @JoinColumn(name="joker_id")
    private Joker joker;
    
    public Joke() {}
    
    public Joke(String name, JokeSeverity severity) {
        this.name = name;
        this.severity = severity;
    }
    
    public Long getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
    
    public JokeSeverity getSeverity() {
        return severity;
    }

    public void setSeverity(JokeSeverity severity) {
        this.severity = severity;
    }

    public Joker getJoker() {
        return joker;
    }

    public void setJoker(Joker joker) {
        this.joker = joker;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Joke other = (Joke) obj;
        if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
            return false;
        }
        if (this.severity != other.severity) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 13 * hash + (this.name != null ? this.name.hashCode() : 0);
        hash = 13 * hash + (this.severity != null ? this.severity.hashCode() : 0);
        return hash;
    }

    @Override
    public String toString() {
        return String.format(TO_STRING_FORMAT, name, severity);
    }
    
    
}
